import React ,{Component} from 'react'
import PropTypes from 'prop-types'
import {
    Form,
    Select,
    Input
  } from 'antd'
  const Item = Form.Item
  const { Option } = Select;
//添加分类的form组件
class AddForm extends Component{

    static proTypes = {
        setForm:PropTypes.func.isRequired,
        categorys:PropTypes.array.isRequired,  // 一级分类数组
        parentId:PropTypes.string.isRequired,  // 父分类id
    }

    componentWillMount(){
        this.props.setForm(this.props.form)
    }

     render(){
      const {categorys, parentId} = this.props
      const { getFieldDecorator } = this.props.form;
      return (
          <form>
          <Item>
          { 
            getFieldDecorator('parentId',{
                initialValue: parentId
             }
            )(
                <Select>
                   <Option value='0'>一级分类</Option>
                   {
                     categorys.map(c=><Option key={c._id} value={c._id}>{c.name}</Option>)
                   }
               </Select>
            )
           }
           {/* Select 的 S 大写*/}
           </Item>
           <Item>
           { 
            getFieldDecorator('categoryName',{
                initialValue: '',
                rules: [
                    {required: true, message: '分类名称必须输入'}
                ]
             }
            )(
               <Input placeholder='请输入分类名称'/>
            )
           }
           </Item>
         </form>
        )
    }
}


export default Form.create()(AddForm)